import time
import qrcode
from PIL import Image,ImageDraw, ImageFont

def test():
    img = Image.open('png/123.png')
    img.show()
    time.sleep(2)
    img.close()


def bakimg():
    # 设置图片的大小和颜色
    width = 1000
    height = 250
    color = (255, 255, 255, 0)  # RGBA格式，最后一个值是透明度，这里是完全透明

    # 创建一个新的图片
    image = Image.new('RGBA', (width, height), 'white')

    # 保存图片到文件
    image.save('png/blank_image.png')

def createqrcode(data):
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_H,
        box_size=10,
        border=2,
    )
    data = data
    qr.add_data(data)
    qr.make(fit=True)
    img = qr.make_image(fill_color="black", back_color="white")
    return img


def addimg():
    qr = createqrcode('123')
    qr_w,qr_h = qr.size
    image = Image.new('RGBA', (1000, 250), 'white')
    image.paste(qr,(0,0))

    draw = ImageDraw.Draw(image)

    # 设置字体样式和大小
    font = ImageFont.truetype('arial.ttf', size=120)

    # 设置文字内容和位置
    text = 'Hello World!'

    # 添加文字
    draw.text((qr_w, 0), text, font=font, fill='red')

    image.show()
addimg()